//
//  LSCupIntegral HeaderView.m
//  LookScore
//
//  Created by nice on 2018/6/22.
//  Copyright © 2018年 ChongQingXunTiCompany. All rights reserved.
//

#import "LSCupIntegralHeaderView.h"
#import "LSCupIntegralModel.h"
@implementation LSCupIntegralHeaderView{
    
    UILabel * _groupLabel;
    UIButton * _btn;
    UIView * _grayView;
}

- (instancetype)initWithReuseIdentifier:(NSString *)reuseIdentifier{
    if (self = [super initWithReuseIdentifier:reuseIdentifier]) {
        [self addContentView];
    }
    return self;
}

- (void)addContentView{
    
    UIView *whiteView = [[UIView alloc] init];
    whiteView.backgroundColor = [UIColor whiteColor];
    [self.contentView addSubview:whiteView];
    whiteView.sd_layout
    .leftEqualToView(self.contentView)
    .topEqualToView(self.contentView)
    .rightEqualToView(self.contentView)
    .heightIs(LSScareValue(30, LSScreenWidth));
    
    UIView *grayView = [[UIView alloc] init];
    grayView.backgroundColor = LSSubGrayColorf7;
    _grayView = grayView;
    [self.contentView addSubview:grayView];
    grayView.sd_layout
    .leftEqualToView(self.contentView)
    .topSpaceToView(whiteView, 0)
    .rightEqualToView(self.contentView)
    .heightIs(LSScareValue(30, LSScreenWidth));
   
    
    UIView * lineView = [[UIView alloc] init];
    lineView.backgroundColor = RGB(92,178,223);
    [whiteView addSubview:lineView];
    lineView.sd_layout
    .leftSpaceToView(whiteView, 13)
    .centerYEqualToView(whiteView)
    .widthIs(4)
    .heightIs(LSScareValue(17, LSScreenWidth));
    
    UILabel *groupLab = [[UILabel alloc] init];
    groupLab.textAlignment = NSTextAlignmentCenter;
    groupLab.textColor = RGB(131,131,131);
    groupLab.font = LSFontSize13;
    [whiteView addSubview:groupLab];
    _groupLabel = groupLab;
    groupLab.sd_layout
    .leftSpaceToView(whiteView, 7)
    .centerYEqualToView(whiteView)
    .autoHeightRatio(0)
    .widthIs(50);
 
    UIButton * btn = [[UIButton alloc] init];
    [btn setTitle:@"返回赛程" forState:UIControlStateNormal];
    [btn setTitle:@"查看积分" forState:UIControlStateSelected];
    btn.titleLabel.font = LSFontSize(13, LSScreenWidth);
    btn.layer.borderWidth = .5f;
    btn.layer.cornerRadius = 5;
    btn.layer.borderColor = RGB(93,93,93).CGColor;
    [btn setTitleColor:RGB(93,93,93) forState:UIControlStateNormal];
    [btn setTitleColor:LSTitleWhiteColor forState:UIControlStateSelected];
    [btn addTarget:self action:@selector(btnClicked:) forControlEvents:UIControlEventTouchUpInside];
    [whiteView addSubview:btn];
    _btn = btn;
    btn.sd_layout
    .rightSpaceToView(whiteView, LSScareValue(14, LSScreenWidth))
    .centerYEqualToView(whiteView)
    .widthIs(LSScareValue(70, LSScreenWidth))
    .heightIs(LSScareValue(26, LSScreenWidth));
    
    NSArray *titleArray = @[@"积分",@"进/失",@"负",@"平",@"胜",@"已赛"];
    
    CGFloat width=(LSScreenWidth-95)/6;
    
    
    float weight = LSScreenWidth/10;
    
    for (NSInteger i = 0; i<6; i++) {
        UILabel * label = [[UILabel alloc] init];
        label.font = [UIFont systemFontOfSize:LSScareValue(13, LSScreenWidth)];
        label.textColor = RGB(180,180,180);
        label.text = titleArray[i];
        label.textAlignment = NSTextAlignmentCenter;
        [grayView addSubview:label];
        label.sd_layout
        .rightSpaceToView(grayView, i*weight)
        .centerYEqualToView(grayView)
        .widthIs(weight)
        .autoHeightRatio(0);
        
    }
    
    UILabel * rankLabel = [[UILabel alloc] init];
    rankLabel.text = @"排名";
    rankLabel.font = LSFontSize13;
    rankLabel.textColor = RGB(180,180,180);
    [grayView addSubview:rankLabel];
    rankLabel.textAlignment = NSTextAlignmentLeft;
    rankLabel.sd_layout
    .leftEqualToView(grayView).offset(13)
    .topEqualToView(grayView)
    .centerYEqualToView(grayView)
    .widthIs(width)
    .heightIs(LSScareValue(30, LSScreenWidth));
    
    
    UILabel * teamLabel = [[UILabel alloc] init];
    teamLabel.text = @"球队";
    teamLabel.textColor = RGB(180,180,180);
    teamLabel.font = LSFontSize12;
    teamLabel.textAlignment = NSTextAlignmentCenter;
    [grayView addSubview:teamLabel];
    teamLabel.sd_layout
    .leftEqualToView(grayView).offset(width+13)
    .topEqualToView(grayView)
    .centerYEqualToView(grayView)
    .widthIs(weight * 2)
    .heightIs(LSScareValue(30, LSScreenWidth));
    
//    UILabel *lable;
//    for (int i=0; i<=7; i++) {
//        lable=[UILabel new];
//        lable.text = titleArray[i];
//        lable.textColor = LSTitleGrayColor3;
//        lable.font=LSFontSize12;
//        lable.textAlignment = NSTextAlignmentCenter;
//        [grayView addSubview:lable];
//
//        if (i==0) {
//            lable.textAlignment = NSTextAlignmentLeft;
//            lable.sd_layout
//            .leftEqualToView(grayView).offset(13)
//            .topEqualToView(grayView)
//            .centerYEqualToView(grayView)
//            .widthIs(width)
//            .heightIs(LSScareValue(30, LSScreenWidth));
//        }else if (i==1){
//            lable.sd_layout
//            .leftEqualToView(grayView).offset(width*i)
//            .topEqualToView(grayView)
//            .centerYEqualToView(grayView)
//            .widthIs(95)
//            .heightIs(LSScareValue(30, LSScreenWidth));
//        }else{
//            lable.sd_layout
//            .leftEqualToView(grayView).offset(width+95+(i-2)*width)
//            .topEqualToView(grayView)
//            .centerYEqualToView(grayView)
//            .widthIs(width)
//            .heightIs(LSScareValue(30, LSScreenWidth));
//        }
//    }
}
- (void)btnClicked:(UIButton *)sender{
    if (self.block) {
        self.block(sender);
    }
}



- (void)setModel:(GroupList *)model{
    
    _model = model;
    
    _groupLabel.text = [NSString stringWithFormat:@"%@组",model.Group];
    if (model.isSelected) {
        _grayView.hidden = YES;
        _btn.selected = YES;
        _btn.backgroundColor = RGB(229,115,94);
        _btn.titleLabel.textColor = LSTitleWhiteColor;
    }else{
        _btn.selected = NO;
        _btn.backgroundColor = LSTitleWhiteColor;
        _btn.titleLabel.textColor = RGB(93,93,93);
        _grayView.hidden = NO;
    }
}

@end
